const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
  .BundleAnalyzerPlugin;
const CompressionPlugin = require("compression-webpack-plugin");

module.exports = {
  publicPath: "./",
  productionSourceMap: false,
  devServer: {
    proxy: {
      "/api": {
        target: "https://192.168.20.124:8001",
        secure: false,
        changeOrigin: true,
        pathRewrite: { "^/api": "" }
      }
    }
  },
  css: {
    loaderOptions: {
      sass: {
        data: `
          @import "./src/assets/css/common.scss";
        `
      },
      less: {
        modifyVars: {
          'primary-color': '#00b1a1',
          'link-color': '#00b1a1',
          'border-radius-base': '2px',
        },
        javascriptEnabled: true
      }
    },
  },
  pwa: {
    iconPaths: {
      favicon32: 'favicon.ico',
      favicon16: 'favicon.ico',
      appleTouchIcon: 'favicon.ico',
      maskIcon: 'favicon.ico',
      msTileImage: 'favicon.ico'
    }
  },
  configureWebpack: config => {
    if (process.env.NODE_ENV === "production") {
      return {
        plugins: [new BundleAnalyzerPlugin()]
      };
    }
  },
  chainWebpack: config => {
    if (process.env.NODE_ENV === "production") {
      // #region 启用GZip压缩
      config
        .plugin("compression")
        .use(CompressionPlugin, {
          asset: "[path].gz[query]",
          algorithm: "gzip",
          test: new RegExp("\\.(" + ["js", "css"].join("|") + ")$"),
          threshold: 10240,
          minRatio: 0.8,
          cache: false
        })
        .tap(args => { });
    }
  },
};
